﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using DocumentManagement.ViewsModels;
using DocumentManagement.Models;
using Microsoft.Win32;
using System.IO;

namespace DocumentManagement.Views
{
    /// <summary>
    /// Interaction logic for ShowItemFileOut.xaml
    /// </summary>
    public partial class ShowItemFileOut : Window
    {
        ShowItemFileOutViewsModel _showItemFileOutViewsModel;
        public ShowItemFileOut(CreateSend sendAttach)
        {
            InitializeComponent();
            _showItemFileOutViewsModel = this.Resources["showItemFileOutViewsModel"] as ShowItemFileOutViewsModel;
            _showItemFileOutViewsModel.MySend = sendAttach;
            dataGrid1.ItemsSource = sendAttach.ScanSendAttacheds.Where(p => p.Active == true).ToList();
        }

        private void DG_Hyperlink_Click(object sender, RoutedEventArgs e)
        {

            TextBlock textblock = sender as TextBlock;
            var send = textblock.DataContext as ScanSendAttached;

            string fileName = "D:\\uploadSend\\";
            SaveFileDialog save = new SaveFileDialog();
            save.FileName = send.FileName;
            save.Filter = "Image files (*.jpg)|*.jpg|Acrobat (*.pdf)| *.pdf|All files (*.*)|*.*";
            var result = save.ShowDialog(); // showdialog มันจะ return true กับ false
            if (result != null)
            {
                if (File.Exists(fileName + send.FileName))
                    File.Copy(fileName + send.FileName, save.FileName, true);
                else
                    MessageBox.Show("File not found");
            }


        }
    }
}
